package com.yanghx.springtarnjms.web;

import com.yanghx.springtarnjms.service.CustomerService;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 客户信息
 *
 * @author yangHX
 * createTime  2019/8/8 20:58
 */
@RestController
@RequestMapping(value = "/api/customer")
public class CustomerResource {

    @Resource
    private JmsTemplate jmsTemplate;

    @Resource
    private CustomerService customerService;


    @PostMapping(value = "/message1/listen")
    public void createMsgWithListener(@RequestBody String msg) {
        jmsTemplate.convertAndSend("customer:msg:new", msg);
    }

    @PostMapping(value = "/message1/direct")
    public void createMsgDirect(@RequestBody String msg) {
        customerService.handle(msg);
    }


    @PostMapping(value = "/message2/listen")
    public void createMsg2WithListener(@RequestBody String msg) {
        jmsTemplate.convertAndSend("customer:msg2:new", msg);
    }


    @PostMapping("/message2/direct")
    public void createMsg2Direct(@RequestBody String msg) {
        customerService.handle2(msg);
    }

    @GetMapping(value = "/message")
    public String getMsg() {
        Object o = jmsTemplate.receiveAndConvert("customer:msg:reply");
        return String.valueOf(o);
    }


}
